<template>
  <div class="home-container">
    <!-- 顶部导航 -->
    <van-nav-bar fixed class="page-nav-bar">
      <van-button to="/search" class="search-btn" slot="title" icon="search" type="primary">搜索</van-button>
    </van-nav-bar>

    <!-- tab标签页面 -->
    <van-tabs v-model="active" class="channel-tabs" animated swipeable>
      <van-tab v-for="item in chanels" :key="item.id" :title="item.name">
        <ArticleList :channeId="item.id" />
      </van-tab>
      <!-- 汉堡菜单 -->
      <div slot="nav-right" class="nav-right">
        <i class="toutiao toutiao-gengduo" @click="isshow=true"></i>
      </div>
      <!-- 背后的占位 -->
      <div slot="nav-right" class="placehoder"></div>
    </van-tabs>
    <van-popup v-model="isshow" closeable close-icon-position="top-left" position="bottom" :style="{ height: '100%' }">
      <ChannelEdit :active="active" @sendData="getEditChannelData" :myChannels='chanels' />
    </van-popup>
  </div>
</template>

<script>
import { getUserChannles } from '@/api/user.js'
import ArticleList from './component/article-list.vue'
import ChannelEdit from './component/channel-edit.vue'
export default {
  data () {
    return {
      active: 1,
      chanels: [],
      isshow: false
    }
  },
  methods: {
    // 加载用户频道数据
    async loadUserChannels () {
      try {
        const res = await getUserChannles()
        // console.log(res)
        this.chanels = res.data.data.channels
      } catch (err) {
        this.$toast('获取频道失败')
      }
    },
    getEditChannelData (e) {
      this.isshow = e.close
      this.active = e.index
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {
    ArticleList,
    ChannelEdit
  },
  created () {
    // 获取子组件的数据函数
    this.loadUserChannels()
  },
  mounted () { }
}
</script>

<style scoped lang='less'>
.home-container {
  padding-bottom: 100px;
  padding-top: 147px;
  .search-btn {
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border-radius: 32px;
    border: none;
  }
  /deep/.van-nav-bar__title {
    max-width: unset;
  }
  /deep/.van-icon {
    color: #fff;
    font-size: 32px;
  }
  /deep/.channel-tabs {
    .van-tabs__wrap {
      position: fixed;
      top: 92px;
      z-index: 2;
      width: 100%;
    }
    .van-tab {
      height: 82px;
      min-width: 200px;
      border-right: 1px solid #edeff3;
      .van-tab__text {
        font-style: 28px;
        color: #777;
      }
    }

    .van-tab--active {
      .van-tab__text {
        font-size: 30px;
        color: #333;
      }
    }

    //条
    .van-tabs__line {
      width: 31px;
      height: 6px;
      background: #3296fa;
      border-radius: 3px;
      bottom: 8px;
    }
    //去除选中条的父盒子的padding值
    .van-tabs__nav {
      padding: 0;
    }

    //tabs右侧的汉堡菜单
    .nav-right {
      width: 66px;
      height: 82px;
      position: fixed;
      right: 0;
      background: rgba(255, 255, 255, 0.9);
      display: flex;
      justify-content: center;
      align-items: center;
      .toutiao {
        font-size: 33px;
      }
      &::before {
        content: '';
        width: 2px;
        height: 82px;
        background-image: url(~@/assets/gradient-gray-line.png);
        position: absolute;
        left: 0;
        background-size: 100% 100%;
      }
    }

    //右侧汉堡菜单背后的占位
    .placehoder {
      width: 66px;
      height: 82px;
      flex-shrink: 0;
    }
  }
}
</style>
